package com.yx.cloud.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yx.cloud.Interface.OnItemClickListener;
import com.yx.cloud.R;
import com.iot.base.bean.account.UserFeedBack;
import com.yx.cloud.utils.RomUtils;

import java.util.List;

public class FeedBackMesListAdapter extends RecyclerView.Adapter implements View.OnClickListener {
    private final static String TAG = "FeedBackMesListAdapter";

    private Context mContext;
    private List<UserFeedBack> mFeedBackMesList;
    private OnItemClickListener mOnItemClickListener = null;
    public FeedBackMesListAdapter(Context context, List<UserFeedBack> list) {
        mContext = context;
        mFeedBackMesList = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View itemView = LayoutInflater.from(mContext).inflate(R.layout.feedbackmeslist_item, parent, false);
        ViewHolder holder = new ViewHolder(itemView);
        itemView.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder) {
            Log.i(TAG, "查询反馈会话列表rrrrr : " + mFeedBackMesList.size());
            UserFeedBack bean = mFeedBackMesList.get(position);
            ((ViewHolder) holder).mTvFeedback_content.setText(bean.getContent());
            ((ViewHolder) holder).mTvFeedback_dateTime.setText(""+bean.getTime());
        }
        ((ViewHolder) holder).itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return mFeedBackMesList.size();
    }
    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(v, (Integer) v.getTag());
        }
    }
    /**
     * Item点击事件方法
     *
     * @param listener
     */
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTvFeedback_content;
        TextView mTvFeedback_dateTime;

        public ViewHolder(View itemView) {
            super(itemView);
            mTvFeedback_content = itemView.findViewById(R.id.tv_feedback_content);
            mTvFeedback_dateTime = itemView.findViewById(R.id.tv_feedback_dateTime);
        }
    }
}
